/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('saasincubator', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ResolveInstanceStatusRequest {
  instanceId?: string(name='InstanceId'),
  meterCode?: string(name='MeterCode'),
  source?: string(name='Source'),
  token?: string(name='Token'),
}

model ResolveInstanceStatusResponseBody = {
  code?: string(name='Code'),
  data?: {
    expireTime?: string(name='ExpireTime'),
    meterCodeRemainingCount?: long(name='MeterCodeRemainingCount'),
    meterCodeUsedCount?: long(name='MeterCodeUsedCount'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  result?: string(name='Result'),
}

model ResolveInstanceStatusResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ResolveInstanceStatusResponseBody(name='body'),
}

async function resolveInstanceStatusWithOptions(request: ResolveInstanceStatusRequest, runtime: Util.RuntimeOptions): ResolveInstanceStatusResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.meterCode)) {
    body['MeterCode'] = request.meterCode;
  }
  if (!Util.isUnset(request.source)) {
    body['Source'] = request.source;
  }
  if (!Util.isUnset(request.token)) {
    body['Token'] = request.token;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ResolveInstanceStatus',
    version = '2022-12-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function resolveInstanceStatus(request: ResolveInstanceStatusRequest): ResolveInstanceStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return resolveInstanceStatusWithOptions(request, runtime);
}

model UpdateMeterRequest {
  instanceId?: string(name='InstanceId'),
  meterCode?: string(name='MeterCode'),
  source?: string(name='Source'),
  token?: string(name='Token'),
}

model UpdateMeterResponseBody = {
  code?: string(name='Code'),
  data?: boolean(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  result?: string(name='Result'),
}

model UpdateMeterResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpdateMeterResponseBody(name='body'),
}

async function updateMeterWithOptions(request: UpdateMeterRequest, runtime: Util.RuntimeOptions): UpdateMeterResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.meterCode)) {
    body['MeterCode'] = request.meterCode;
  }
  if (!Util.isUnset(request.source)) {
    body['Source'] = request.source;
  }
  if (!Util.isUnset(request.token)) {
    body['Token'] = request.token;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'UpdateMeter',
    version = '2022-12-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateMeter(request: UpdateMeterRequest): UpdateMeterResponse {
  var runtime = new Util.RuntimeOptions{};
  return updateMeterWithOptions(request, runtime);
}

